﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;

namespace XNADota.Input
{
    public class InputManager : GameComponent
    {
        public delegate void ProcessInputHandler(GameTime gameTime, InputState inputState);

        private InputState _InputState;

        private Dictionary<Object, ProcessInputHandler> _HandlerList;

        public InputState InputSate
        {
            get { return _InputState; }
        }
        public InputManager(Game game) : base(game)
        {
            _HandlerList = new Dictionary<Object, ProcessInputHandler>();
            _HandlerList.Clear();

            _InputState = new InputState(game);
        }

        public override void Update(GameTime gameTime)
        {
            _InputState.Update();

            foreach (ProcessInputHandler ProcessInput in _HandlerList.Values)
            {
                ProcessInput(gameTime, _InputState);
            }

            base.Update(gameTime);
        }

        public void Add(IInputHandler InputHandler)
        {
            _HandlerList.Add(InputHandler, InputHandler.ProcessInput);
        }
    }
}